{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "d60eb688",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号:lxl\n",
      "密码:lxl\n",
      "请输入您的工资:20000\n",
      "0 ('牛排', 1000)\n",
      "1 ('红酒', 400)\n",
      "2 ('水果', 300)\n",
      "please choose your things:0\n",
      "Added 0 into shopping cart,您的余额为 19000\n",
      "0 ('牛排', 1000)\n",
      "1 ('红酒', 400)\n",
      "2 ('水果', 300)\n",
      "please choose your things:1\n",
      "Added 1 into shopping cart,您的余额为 18600\n",
      "0 ('牛排', 1000)\n",
      "1 ('红酒', 400)\n",
      "2 ('水果', 300)\n",
      "please choose your things:2\n",
      "Added 2 into shopping cart,您的余额为 18300\n",
      "0 ('牛排', 1000)\n",
      "1 ('红酒', 400)\n",
      "2 ('水果', 300)\n",
      "please choose your things:ok\n",
      "--------shopping list-------------!\n",
      "('牛排', 1000)\n",
      "('红酒', 400)\n",
      "('水果', 300)\n",
      "所剩余额是： 18300\n"
     ]
    }
   ],
   "source": [
    "user1=\"lxl\"\n",
    "password1 = \"lxl\"\n",
    "\n",
    "username = input(\"账号:\")\n",
    "password = input(\"密码:\")\n",
    "\n",
    "#Author:Kelly\n",
    "shopping_list=[]\n",
    "listGoods = [(\"牛排\",1000),(\"红酒\",400),(\"水果\",300)]\n",
    "salary = input(\"请输入您的工资:\")\n",
    "if salary.isdigit():\n",
    "    salary = int(salary)\n",
    "# for item in listGoods:\n",
    "#     print(listGoods.index(item),item)#取下标\n",
    "    while True:\n",
    "        for index,item in enumerate(listGoods):#取下标\n",
    "            print(index,item)\n",
    "        user_choice = input(\"please choose your things:\")\n",
    "        if user_choice.isdigit():\n",
    "            user_choice = int(user_choice)\n",
    "            if user_choice <= len(listGoods) and user_choice >= 0:\n",
    "                p_item = listGoods[user_choice]\n",
    "                if p_item[1] <= salary: #买得起\n",
    "                    shopping_list.append(p_item)\n",
    "                    salary -= p_item[1]\n",
    "                    print(\"Added %s into shopping cart,您的余额为 %s\"%(user_choice,salary))\n",
    "                else:\n",
    "                    print(\"余额不足！\")\n",
    "            else:\n",
    "                print(\"所选的商品无效！\")\n",
    "        elif user_choice == 'ok':\n",
    "            print('--------shopping list-------------!')\n",
    "            for p in shopping_list:\n",
    "                print(p)\n",
    "            print(\"所剩余额是： %s\"%(salary))\n",
    "            break\n",
    "        else:\n",
    "            print(\"invalid option\")\n",
    "else:\n",
    "    print(\"invalid option\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "71c486fb",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
